﻿/*
	Copyright 2008 CATsoft Development GmbH

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
/*
	Display functions
*/

/***********************************************************************
 Showing entries
***********************************************************************/
function showItems(){
	var s,t;
	var today = new Date();
	var hm;
	var due;
  var days;
	var itemsVisible = false;

	if( ! feedsDefined )
	{
		info.innerText = NO_FEED

		view.height = 60;
		info.visible = true;
		listDiv.visible = false;
	}
	else 
	{
		items.sort( sortItems );
		info.visible = false;
		listDiv.visible = true;
		itemlist.removeAllElements();

		for( var i = 0; i < items.length; i++){
			var feed = getFeed( items[i].feedurl ); 
			if( feed != null){
				if(( ! items[i].read) && (feed.lastread < items[i].date))
				{
					itemsVisible = true;
					AddItem( i, items[i].title, items[i].description, items[i].link);
				}
			}
		}
		if( ! itemsVisible ){
			listDiv.visible = false;
			info.visible = true;
			info.innerText = NO_ITEMS;
		}
	}
}

/***********************************************************************
	Add Item to display
***********************************************************************/
function AddItem( itemIndex, title, description, link) {
var	labelwidth = itemlist.width - 24;
var 	baseUrl

	labelwidth += 16;
	i = link.indexOf( "://" )
	i = link.indexOf( "/", i + 3 )
	if( i>=0)
		baseUrl = link.substring( 0, i  );
	else
		baseUrl = link;
	baseUrl = baseUrl + "/favicon.ico"
	
	entry = "<item height=\"20\" width=\"" + itemlist.width + "\" name=\"" + itemIndex + "\" ondblclick=\"itemDoubleClick(" + itemIndex + ", '" + link + "')\" onrclick=\"itemRightClick(" + itemIndex + ")\">";
	entry = entry + "<label x=\"0\" width=\"" + labelwidth + "\" color=\"#000000\" tooltip=\"" + title + "\n" + description+ "\" font=\"Tahoma\" size=\"8\">" + title + "</label>";
	entry = entry + "</item>";
	itemlist.AppendElement( entry );
	
return 1;
}

/***********************************************************************
  Scrollbar
***********************************************************************/
function sbOnChange(){
	itemlist.height = items.length * itemlist.itemHeight;
	sb.max= items.length * itemlist.itemHeight - listDiv.height;
	if (sb.max<0)
	sb.max=0;
	itemlist.y=-sb.value;
}

/***********************************************************************
  Resize Views
***********************************************************************/
function view_onsize() {
	contentArea.width = view.width - 4;
	contentArea.height = view.height - 4;
	listDiv.width = contentArea.width;
	listDiv.height = contentArea.height - listDiv.y - 4;

	itemlist.width = listDiv.width - 20 ;
	itemlist.height = listDiv.height + 40;
	sb.height = listDiv.height - 4;
	sb.x = itemlist.width + 1;

	info.y = (contentArea.height - info.height) / 2;

	itemlist.itemwidth = itemlist.width;

}

